package cn.kgc.service.impl;

import cn.kgc.entity.Industry;
import cn.kgc.mapper.IndustryMapper;
import cn.kgc.service.IndustryService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @author k
 */
@Slf4j
@Service("industryService")
@SuppressWarnings("all")
public class IndustryServiceImpl extends ServiceImpl<IndustryMapper, Industry> implements IndustryService {
    @Override
    public List<String> getTopIndustryId() {
        //查询一级行业信息的ID
        LambdaQueryWrapper<Industry> industryLambdaQueryWrapper = new LambdaQueryWrapper<>();
        industryLambdaQueryWrapper.select(Industry::getId);
        industryLambdaQueryWrapper.eq(Industry::getLevel,1);
        List<Industry> lists=list(industryLambdaQueryWrapper);
        //将查询到的ID集合转换成List<String>
        return lists.stream().map(Industry::getId).collect(Collectors.toList());
    }

    @Override
    public List<Industry> getTopIndustry() {
        LambdaQueryWrapper<Industry> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(Industry::getFatherId, 0);
        queryWrapper.orderByAsc(Industry::getSort);
        return list(queryWrapper);
    }

    @Override
    public List<Industry> getThirdIndustry(String fatherId) {
        return getBaseMapper().selectThirdLevleIndustry(fatherId);
    }
}